package handler

import (
	"SteedCensorShield/internal/logic"
	"SteedCensorShield/models"
	"net/http"

	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
)

func CheckText(c *gin.Context) {
	// 解析请求
	var request models.FilterInfo
	if err := c.BindJSON(&request); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}

	// 检查敏感词
	filteredWords, err := logic.CheckSensitiveWord(request.ChatDetail)
	if err != nil {
		c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
		return
	}

	// 设置处理结果
	request.Result = "checked"
	// TODO: 保存过滤结果
	// request.Filters = filteredWords

	// 打印filteredWords的内容
	log := logrus.New()
	log.SetFormatter(&logrus.JSONFormatter{}) // 设置日志输出格式为JSON
	log.Info("filteredWords:", filteredWords)

	// filteredWords 打印详细日志
	request.Filters = []string{""}

	// 返回结果
	c.JSON(http.StatusOK, request)
}
